package router

import (
	"github.com/gin-gonic/gin"
	"zg4zk2/client/client"
	"zg4zk2/client/enit"
	"zg4zk2/common/proto/user"
)

func SendSms(c *gin.Context) {
	var data enit.SendSms
	err := c.ShouldBind(&data)
	if err != nil {
		c.JSON(200, gin.H{
			"code": 1000,
			"data": err.Error(),
		})
		return
	}
	sms, err := client.SendSms(c, &user.SendSmsReq{
		Mobile: data.Mobile,
		Source: data.Source,
	})
	if err != nil {
		c.JSON(200, gin.H{
			"code": 1000,
			"data": err.Error(),
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 0,
		"data": sms,
	})
}

func Login(c *gin.Context) {
	var data enit.Login
	err := c.ShouldBind(&data)
	if err != nil {
		c.JSON(200, gin.H{
			"code": 1000,
			"data": err.Error(),
		})
		return
	}
	login, err := client.Login(c, &user.LoginReq{
		Mobile:   data.Mobile,
		Password: data.Password,
		Code:     data.Code,
	})
	if err != nil {
		c.JSON(200, gin.H{
			"code": 1000,

			"data": err.Error(),
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 2,
		"data": login,
	})

}
